﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apex.Common.MVVM
{
    public interface IViewModel : INotifyPropertyChanged
    {
        
    }

    public interface IViewModel<T> : IViewModel
    {
        T Model { get; set; }
    }

    public class ViewModel<T> : IViewModel<T>
    {
        private T _model;

        public T Model
        {
            get { return _model; }
            set { _model = value; OnPropertyChanged("Model"); }
        }

        #region INPC

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (string.IsNullOrEmpty(propertyName))
                throw new ArgumentException("Property name must not be null or empty.");

            if (PropertyChanged == null)
                return;

            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        public ViewModel()
        {

        }

        public ViewModel(T model)
        {
            _model = model;
        }
    }
}
